package com.ddtech.business.course.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ddtech.business.common.BaseService;
import com.ddtech.business.course.entity.CourseGrade;
import com.ddtech.business.course.mapper.CourseGradeMapper;
import com.ddtech.business.course.query.CourseGradeQuery;
import com.ddtech.business.course.service.CourseGradeService;
import com.ddtech.utils.PageUtil;
import com.ddtech.utils.SecurityUtils;
import org.springframework.stereotype.Service;

/**
 * @version v1.0
 * @ClassName:CourseGradeServiceImpl description：
 * @author:wei_zhang(xiao)
 * @date: 2023-06-02 15:04
 */
@Service
public class CourseGradeServiceImpl extends BaseService<CourseGradeMapper, CourseGrade> implements CourseGradeService {
    /**
     * description: 新增评分
     * @param:  * @param courseGrade
     * @date: 2023-06-02
     * @return: void
     * @version v1.0
     * @author:wei_zhang(xiao)
     */
    @Override
    public void create(CourseGrade courseGrade) {
        courseGrade.init();
        courseGrade.setUserId(SecurityUtils.getUserId());
        courseGrade.setUserName(SecurityUtils.getName());
        courseGrade.setAvatar(SecurityUtils.getUserAvatar());
        this.saveOrUpdate(courseGrade);
    }

    /**
     * description: 查询课程评论
     * @param:  * @param courseGradeQuery
     * @date: 2023-06-02
     * @return: java.lang.Object
     * @version v1.0
     * @author:wei_zhang(xiao)
     */
    @Override
    public Object pageCourseGradeListPc(CourseGradeQuery courseGradeQuery) {
        IPage<CourseGrade> page = this.page(courseGradeQuery.populatePage(), courseGradeQuery.autoWrapper());
        return PageUtil.toPage(page.getRecords(), page.getTotal());
    }
}
